{% extends "xadmin/base_site.html" %}
{% load i18n %}
{% load url from future %}
{% load xadmin_tags %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
{% if account_view %}
<ul class="breadcrumb">
  <link href="/websys/static/xadmin/vendor/bootstrap-table/css/bootstrap-table.min.css" type="text/css" media="screen" rel="stylesheet" />
<li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li class="active"> {{ title }} </li>
</ul>
{% else %}
<ul class="breadcrumb">
  <li><a href="{% url 'xadmin:index' %}">{% trans 'Home' %}</a></li>
  <li>
    {% if has_view_permission %}
    <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
    {% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %}
  </li>
  <li><a href="{% url opts|admin_urlname:'change' original.pk %}">{{ original|truncatewords:"18" }}</a></li>
  <li class="active">{% trans 'Change password' %}</li>
</ul>
{% endif %}
{% endblock %}

{% block content-nav %}
{% endblock %}
{% block content %}
<!--页面设计在这儿....{{ serverval }}-->
    <style>
    .tb_tr{height: 50px; border:gainsboro 1px  double;}
    .tb_td{height: 50px; border: gainsboro 1px double; width:80px;}
    </style>
    <table style="width: 100%">
        <tr class="tb_tr" id="tr_day" >
            <td class="tb_td">日期：</td>
            <td>
                <input type="text" id="day_0" class="datepicker" placeholder="请选择日期" />
                到
                <input type="text" id="day_1" class="datepicker" placeholder="请选择日期" />
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td">渠道：</td>
            <td>
                <select id="sel_qudao" multiple="true" style="width: 150px;height: 120px">
                   {% for key,value in channel.items %}
                            <option value="{{ value }}">{{ key }}</option>
                    {% endfor %}
                </select><span>注:可按住Ctrl进行多选!</span>
            </td>
        </tr>
        <tr class="tb_tr">
            <td class="tb_td">服务器：</td>
            <td>
                <select id="sel_pf">
                    <option value="" selected="selected">请选择</option>
                    {% for item in htmldata.apps %}
                            <option value="{{ item.pf }}">{{ item.name }}</option>
                    {% endfor %}
                </select>
            </td>
        </tr>
    <tr class="tb_tr" >
            <td class="tb_td">道具id：</td>
            <td>
                <input type="text" id="txt_id" maxlength="10" />
            </td>
        </tr>

    <tr class="tb_tr">
            <td class="tb_td"></td>
            <td><label id="la_link"> {{links}}</label>&nbsp;&nbsp;<input type="button" id="bt_copy" value="查询" onclick="toSearch()"></td>
        </tr>

    <tr class="tb_tr">
            <td class="tb_td" colspan="2">
                <table data-toggle="table" data-height="100%"  data-pagination="true" id="table_report" style="">
<!--                     thead>
                        <tr>
                            <th data-rowspan="2" data-field="id">道具ID</th>
                            <th data-rowspan="2" data-field="name">道具名称</th>
                            <th data-colspan="4">购买数量</th>
                            <th data-colspan="4">购买人数</th>
                            <th data-colspan="4">收入</th>
                        </tr>
                        <tr>
                            <th  data-field="amount_today">今日</th>
                            <th  data-field="amount_yestoday">昨日</th>
                            <th  data-field="amount_trend">趋势</th>
                            <th  data-field="amount_average">三日平均</th>

                            <th  data-field="people_today">今日</th>
                            <th  data-field="people_yestoday">昨日</th>
                            <th  data-field="people_trend">趋势</th>
                            <th  data-field="people_average">三日平均</th>

                            <th  data-field="income_today">今日</th>
                            <th  data-field="income_yestoday">昨日</th>
                            <th  data-field="income_trend">趋势</th>
                            <th  data-field="income_average">三日平均</th>
                        </tr>
                    </thead -->
                </table>
            </td>
    </tr>
    </table>
<script type="text/javascript" src="/websys/static/xadmin/vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
    <script src="/websys/static/xadmin/vendor/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
    <script src="/websys/static/xadmin/vendor/bootstrap-table/js/bootstrap-table.min.js"></script>
    <script src="/websys/static/xadmin/vendor/bootstrap-table/js/bootstrap-table-locale-all.min.js"></script>
    <script>
    var tb_title_obj={
        'share':['金额'],
        'table':['房数']
    };

    var pagType='{{ htmldata.type }}';
    var dateType=new Array('year','month','day');
    var dateName={'year':'年份','month':'月份','day':'日期'};
    var curType='day';
    function setType(val)
    {//alert(val);
        for(var ii=0;ii<dateType.length;ii++)
        {
            if(ii==val)
            {
                $('#tr_'+dateType[val]).css('display', '');
            }
            else
            {
                $('#tr_'+dateType[ii]).css('display', 'none');
            }
            curType=dateType[val];
        }
    }
    function setDay()
    {//alert('month');
        for(var ii=0;ii<2;ii++) {
            $("#day_"+ii).datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                clearBtn: true,//清除按钮
                //todayBtn: true,//今日按钮
                startView: 'days',
                maxViewMode: 'days',
                minViewMode: 'days',
                format: "yyyy-mm-dd"//日期格式，详见 http://bootstrap-datepicker.readthedocs.org/en/release/options.html#format
            });
            $("#day_"+ii ).datepicker( 'setDate' , new Date());
        }
    }


    $(function () {
        //setYear();
        //setMonth();
        setDay();

        $(".date-picker").datepicker({
                language: "zh-CN",
                autoclose: true,
            });

        //initStoreJson();
    });

    function toSearch()
    {
        var t_pf=$("#sel_pf").val();
        // if(t_pf=='')
        // {
        //     alert('服务器不能为空');
        //     return
        // }
        var str = '';

        var select = document.getElementById("sel_qudao");
        //var str = [];

        for(i=0;i<select.length;i++){
            if(select.options[i].selected){
            str=str+select[i].value+',';
            }
        }

    if (str==''){
        alert('请选择渠道!');return;
    }
        //var t0=$("#date_0").datepicker("getDate").toLocaleString();//获取
        //$(".datepicker").datepicker("setDate", '2014-01-25');//设置
        var t0=$("#"+curType+"_0").val(),t1=$("#"+curType+"_1").val();
        var t2=$("input[name='r_type']:checked").val();
        var tid=$('#txt_id').val();

        //alert(t0+"-"+t1+"开发中。"+t2);//data-url="/websys/static/data2.txt"
        var turl='/xadmin/ajax_report/props';//?date='+t0+','+t1+'&type='+t2;
        if(t0=='' || t1=='')
        {
            alert('日期不能为空');
            return;
        }
        $('#table_report').bootstrapTable('destroy'); // 显示之前，先把当前表格销毁
        $('#table_report').bootstrapTable({
            //search: true,
            locale:'zh-CN',//中文支持
            sortable: true,      //是否启用排序
            //showFooter:true,
            sortName:'date',
            //showRefresh: true,
            pagination: true,//是否开启分页（*）
             pageNumber:1,//初始化加载第一页，默认第一页
             pageSize: 10,//每页的记录行数（*）
              pageList: [10,20,50],//可供选择的每页的行数（*）
            method: "get",         // 经过测试，只有post方法能发给后端的helloWorld.do
            showExport: true,                     //是否显示导出
            exportDataType: "basic",              //basic', 'all', 'selected'.
            //sidePagination: 'server',
            queryParamsType:'', //默认值为 'limit' ,在默认情况下 传给服务端的参数为：offset,limit,sort
　　// 设置为 ''  在这种情况下传给服务器的参数为：pageSize,pageNumber
            queryParams: function (params) {
                return {
                    //meterID: $('#meterid').val(),
                    pageSize: params.pageSize,
                    //offset: params.offset,
                    pageNumber:params.pageNumber,
                    sortOrder: params.order,
                    sort: params.sort, //排序列名
                    date: t0+','+t1,
                    pf:t_pf,
                    tid:tid,
                    channel:str
                }
            },

            url:turl,   // 发送到后端helloWorld.do，由helloWorld.do返回json字符串，
                                    // 必须是列表形式，例如：[{"name":"aaa","id":"kkk"},{...},...]
            columns:[{              // 定义过滤的字符串，只有columns里写的才显示，其它不显示
                field: 'id',        // 这里是需要显示的字段的key,也就是helloWorld.do返回json字符串
                                    // 中必须有这个key,以及对应的value
                title: '道具id',         // 在页面显示的该列的标题信息
                footerFormatter:'合计',

              },
                    {
                field: 'item_name',
                title: '道具名称',
                //footerFormatter:'合计',
                //formatter: nameFormatter
              },
                {
                    field: 'num',
                    title: '购买数量',
                    footerFormatter: function (value) {
                        return toSum(value,'num');
                    }
                },
                {
                    field: 'count',
                    title: '购买人数',
                    footerFormatter: function (value) {
                        return toSum(value,'count');
                    }
                },
                {
                    field: 'amt',
                    title: '收入',
                    footerFormatter: function (value) {
                        return toSum(value,'amt');
                    }
                }

            ],

        });

        /*
        $table.bootstrapTable('load', data);
        $('#table_report').bootstrapTable({
                url: 'http://127.0.0.1:8080/xadmin/report/recharge?date='+t0+','+t1+'&type='+t2
            });*/
    }
    //读取json商场列表
    // var store_obj;
    // function initStoreJson()
    // {
    //     $.getJSON("/websys/static/gamejson/store.json", function (data) {
    //         store_obj=data;
    //         //alert(store_obj);
    //     });
    // }
    // //名称列
    // function nameFormatter(value, row, index)
    // {
    //     var t_reason=row.reason;
    //     var t_prekey='';
    //     if(t_reason.indexOf('VIP')>-1)
    //     {
    //         t_prekey='VIP_';
    //     }
    //     return store_obj[t_prekey+'SHOP_INFO'][row.id]['item_name'];//+'('+t_prekey.replace('_','')+')';
    //  }
    //合计
    function toSum(arr,key)
    {
        var t_count=0;
        for (var i in arr) {
            var tmp_num=arr[i][key];
            t_count+=tmp_num;
        }
        return t_count;
    }
    </script>
{% endblock %}